home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c++-part2 / 18208 < prev    next >
Encoding:
Internet Message Format  |  1996-08-05  |  2.1 KB

  1. Path: ix.netcom.com!netnews
  2. From: miker3@ix.netcom.com (Mike Rubenstein)
  3. Newsgroups: comp.lang.c++
  4. Subject: Re: Pure virtual destructors?
  5. Date: Fri, 19 Apr 1996 04:24:48 GMT
  6. Organization: Netcom
  7. Message-ID: <3177148b.107663632@nntp.ix.netcom.com>
  8. References: <4kuq0i$p6t@ftp.ee.vill.edu> <3175BDF5.5ADC81B5@eiffel.com>
  9. NNTP-Posting-Host: ix-dc13-16.ix.netcom.com
  10. X-NETCOM-Date: Thu Apr 18  9:25:03 PM PDT 1996
  11. X-Newsreader: Forte Agent .99d/32.182
  12.  
  13. "Guus Leeuw jr." <guusl@eiffel.com> wrote:
  14.  
  15. > sheridan@monet.vill.edu wrote:
  16. > > 
  17. > > The rule with destructors is that they are always overridden, right?
  18. > > That's a quote from VC4 docs, BTW.  When I do this:
  19. > > 
  20. > > class CBase {
  21. > > public:
  22. > >     virtual ~CBase() = 0;
  23. > > ...};
  24. > > 
  25. > > class CChild : public CBase {
  26. > > public:
  27. > >     ~CChild();
  28. > > ...};
  29. > > 
  30. > > and declare a body for ~CChild, I always get unresolved external on
  31. > > CBase::~CBase.  I have seen this in several cases.  My guess is it's not
  32. > > a compiler bug, so what am I missing?
  33. > Here is what the working paper of the ANSI comittee on destructors says (sec.
  34. > 12.4.6):
  35. > "Destructors are not inherited. A destructor can be declared virtual or pure
  36. > virtual; if any objects of that class or any derived class are created in the
  37. > program, the destructor shall be defined. If a class has a base class with a
  38. > virtual destructor, its destructor (whether user- or implicitly-declared) is
  39. > virtual."
  40. > Which means: You cannot have a pure virual destructor in CBase. It can be
  41. > virtual, though, for a virtual destructor still comes with a definition.
  42.  
  43. Huh?  You quote the standard as saying that you can have a pure
  44. virtual destructor and use that for justification for your claim that
  45. you cannot have a pure virtual destructor.
  46.  
  47. You certainly may have a pure virtual destructor.  Unlike other pure
  48. virtual member functions, a pure virtual destructor must be
  49. implemented if any instances of a derived class are created.  For
  50. other pure virtual functions the implementation is not required by the
  51. language (it may, of course, be needed by the semantics of the class
  52. being defined).
  53.  
  54. Michael M Rubenstein
  55.